package com.siteseat.common.security;

import com.siteseat.common.foundation.Component;
import com.siteseat.common.foundation.PropertyHelper;

/**
 *
 */
public abstract class SecureComponent extends Component {
  
  private SecurityManager securityManager;
  
  /**
   * Gets the securityManager
   *
   * @return the securityManager
   */
  public SecurityManager getSecurityManager() {
    return securityManager;
  }

  /**
   * Sets the securityManager
   *
   * @param securityManager the securityManager to set
   */
  public void setSecurityManager( SecurityManager securityManager ) {
    this.securityManager = securityManager;
  }
  
  /**
   * 
   *
   * @param actor
   * @param resource
   * @param permission
   * @throws SecurityException
   */
  public void ensureGranted( String actor, String resource, Permission permission ) throws SecurityException {
    getSecurityManager().ensureGranted( actor, resource, permission );
  }

  /**
   * 
   *
   * @param credentialName
   * @param resource
   * @param permission
   * @return
   * @throws SecurityException
   */
  public boolean isGranted( String credentialName, String resource, Permission permission ) throws SecurityException {
    return getSecurityManager().isGranted( credentialName, resource, permission );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected void doInit() throws Exception {
    PropertyHelper.ensureInitialized( log, getSecurityManager(), "securityManager" );
  }

}
